package demo2;

import java.util.concurrent.TimeUnit;

public class synchronized1 {
    public static void main(String[] args) throws InterruptedException {
        D1 d1 = new D1();
        new Thread(()->{
            d1.func2();//锁的是d1对象
        }).start();
        new Thread(()->{
            d1.func1();
        }).start();

        new Thread(()->{
                d1.staticFun1();//静态方法,锁定的是D1类
        }).start();

//        TimeUnit.SECONDS.sleep(5);
    }

}

class D1{
    public synchronized void func1(){
        System.out.println("exec fun1");
    }

    public synchronized void func2() {
        try {
//            notify();
            TimeUnit.SECONDS.sleep(3);
            System.out.println("exec fun2");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public synchronized static void staticFun1(){
        System.out.println("exec staticFun1");
    }


}
